//
//  LGBasicInfoCommonCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/9/13.
//

#import "LGBasicInfoCommonCell.h"

@interface LGBasicInfoCommonCell()
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UIImageView *vipView;
/**   */
@property (nonatomic , strong)UIImageView *tipView;
/**   */
@property (nonatomic , strong)NSDictionary *vipWidth;

@end

@implementation LGBasicInfoCommonCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.vipWidth = @{@"1":@(16),@"2":@(32),@"3":@(48),@"4":@(64)};
        [self createSubView];
    }
    return  self;
}

-(void)setType:(LGPositionType)type{
    [super setType:type];
    CGFloat top = viewPix(14);
    CGFloat bottom = -viewPix(14);
    if (type == LGPositionTypeTop) {
        top = viewPix(22);
    }else if (type == LGPositionTypeBottom){
        bottom = -viewPix(22);
    }
    [self.contentLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(top);
        make.bottom.equalTo(self.contentView).offset(bottom);
    }];
}

-(void)setShowTip:(BOOL)showTip{
    _showTip = showTip;
    CGFloat width = (showTip == YES)?viewPix(16):0;
    [self.tipView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(width));
    }];
}

-(void)setVipLevel:(NSString *)vipLevel{
    _vipLevel = vipLevel;
    self.vipView.image = [UIImage imageNamed:[NSString stringWithFormat:@"vip_icon_%@",vipLevel]];
}

-(void)setTitle:(NSString *)title{
    _title = title;
    self.titleLabel.text = title;
    CGFloat titleWidth = [title textWidthWithFont:LGFont(16) maxHeight:MAXFLOAT];
    [self.titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(titleWidth+5));
    }];
}

-(void)setContent:(NSString *)content{
    _content = content;
    CGFloat vipWidth = [self.vipWidth.allKeys containsObject:self.vipLevel]?[self.vipWidth[self.vipLevel] floatValue]:0;
    [self.vipView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(vipWidth));
    }];
    
    self.contentLabel.text = (content.length>0)?content:@" ";
    CGFloat width = [self.contentLabel.text textWidthWithFont:LGFont(16) maxHeight:MAXFLOAT]+3;
    width = width>(Screen_W-viewPix(155)-vipWidth)?(Screen_W-viewPix(155)-vipWidth):width;
    [self.contentLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(width));
    }];
}

-(void)setStatus:(NSString *)status{
    _status = status;
    self.statusLabel.text = status;
    CGFloat width = [status textWidthWithFont:LGFontWeight(16, UIFontWeightMedium) maxHeight:MAXFLOAT];
    [self.statusLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(width));
    }];
}


#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.contentLabel];
    [self.contentView addSubview:self.statusLabel];
    [self.contentView addSubview:self.vipView];
    [self.contentView addSubview:self.tipView];

    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.baseView).offset(viewPix(12));
        make.top.equalTo(self.contentLabel);
        make.width.equalTo(@(viewPix(60)));
    }];
    [self.vipView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentLabel.mas_left).offset(-viewPix(4));
        make.centerY.equalTo(self.titleLabel);
        make.width.equalTo(@(16));
        make.height.equalTo(@(16));
    }];
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(viewPix(14));
        make.bottom.equalTo(self.contentView).offset(-viewPix(14));
        make.right.equalTo(self.statusLabel.mas_left).offset(-viewPix(5));
        make.width.equalTo(@(viewPix(100)));
    }];
    [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentLabel);
        make.right.equalTo(self.tipView.mas_left);
        make.width.equalTo(@(0));
    }];
    
    [self.tipView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.width.height.equalTo(@(viewPix(16)));
        make.centerY.equalTo(self.contentLabel);
    }];
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"" colorString:@"#606266" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
        [_titleLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
    }
    return _titleLabel;
}

-(UILabel *)contentLabel{
    if(!_contentLabel){
        _contentLabel = [UILabel lableWithText:@" " colorString:@"#282828" textFont:LGFont(16) textAlignment:NSTextAlignmentRight lines:0];
        [_contentLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
    }
    return _contentLabel;
}

-(UILabel *)statusLabel{
    if(!_statusLabel){
        _statusLabel = [UILabel lableWithText:@" " colorString:@"#282828" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentRight lines:1];
        [_statusLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
    }
    return _statusLabel;
}

-(UIImageView *)vipView{
    if(!_vipView){
        _vipView = [[UIImageView alloc] init];
    }
    return _vipView;
}

-(UIImageView *)tipView{
    if(!_tipView){
        _tipView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"grayTip16"]];
    }
    return _tipView;
}



@end
